﻿<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <meta charset="utf-8"/>
    <link href="css/default.css" rel="stylesheet"/>
    <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="js/common.js"></script>

    <script type="text/javascript">
        function stop() {
            var request_data = GetRequest();
            var dbid = request_data["dbid"];
            url = "/upstate_camera_state/" + dbid + "/" + 0;
            $.ajax({
                type: "GET",
                url: url,
                success: function (result) {
                    if (result.data) {
                        $("#lab_state").text("禁用");
                        $("#btn_stop").hide();
                        $("#btn_start").show();
                    }
                }
            });
        }
        ;

        function start() {
            var request_data = GetRequest();
            var dbid = request_data["dbid"];
            url = "/upstate_camera_state/" + dbid + "/" + 1;
            $.ajax({
                type: "GET",
                url: url,
                success: function (result) {
                    if (result.data) {
                        $("#lab_state").text("正常");
                        $("#btn_stop").show();
                        $("#btn_start").hide();
                    }
                }
            });
        }
        ;
    </script>

    <script type="text/javascript">

        $(document).ready(function () {
            var request_data = GetRequest();
            var dbid = request_data["dbid"];
            url = "get_camera/" + dbid;
            $.ajax({
                type: "GET",
                url: url,
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    if (result.data != null) {
                        $("#id").val(result.data.Id);
                        $('#address').val(result.data.Address);
                        $("#port").val(result.data.Port);
                        $("#user_name").val(result.data.UserName);
                        $("#camera_pass_word").val(result.data.PassWord);
                        $("#select_camera").val(result.data.TypeId);
                        if (result.data.Vaild == 1) {
                            $("#lab_state").text("正常");
                            $("#btn_stop").show();
                            $("#btn_start").hide();
                        }
                        else {
                            $("#lab_state").text("禁用");
                            $("#btn_stop").hide();
                            $("#btn_start").show();
                        }

                    }
                }
            });
        });

    </script>

    <script type="text/javascript">
        function save() {

            var id = $("#id").val();
            if (id == "") {
                alert("摄像机名称不能为空");
                return;
            }

            var type_id = $('#select_camera').val();

            var address = $('#address').val();
            if (address == "") {
                alert("请填写IP");
                return;
            }
            else {
                if (!isIP(address)) {
                    alert("IP地址错误");
                    return;
                }
            }
            var port = $("#port").val();
            if (port == "") {
                alert("端口不能为空");
                return;
            } else {
                if (!isZZ(port)) {
                    alert("端口必须为正整数");
                    return;
                }
            }
            var user_name = $("#user_name").val();
            if (user_name == "") {
                alert("请填写用户名");
                return;
            }
            var camera_pass_word = $("#camera_pass_word").val();
            if (camera_pass_word == "") {
                alert("请填写密码");
                return;
            }
            url = "/update";
            var request_data = GetRequest();
            data = {
                "type_id": type_id,
                "pass_word": camera_pass_word,
                "user_name": user_name,
                "port": port,
                "id": id,
                "dbid": request_data["dbid"],
                "address": address
            };

            $.ajax({
                type: "post",
                url: url,
                data: JSON.stringify(data),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    alert(JSON.stringify(result));
                }
            });

        }
    </script>
</head>
<body>
<table class="Cam_table">
    <th colspan="6"> 摄像机配置：</th>

    <tr>
        <td class="Td1">名称：</td>
        <td><input id="id" type="text"/></td>
    </tr>

    <tr>
        <td class="Td1">摄像机类型：</td>
        <td>
            <select id="select_camera">
                <option value="HIK">海康</option>
                <option value="DAHUA">大华</option>
                <option value="USB">本地USB</option>
                <option value="FILE">本地文件</option>
            </select>
        </td>
    </tr>
    <tr>
        <td class="Td1">IP：</td>
        <td><input id="address" type="text"/></td>
    </tr>
    <tr>
        <td class="Td1">端口：</td>
        <td><input id="port" type="text"/></td>
    </tr>
    <tr>
        <td class="Td1">用户名：</td>
        <td><input id="user_name" type="text"/></td>
    </tr>
    <tr>
        <td class="Td1">密码：</td>
        <td><input id="camera_pass_word" type="text"/></td>
    </tr>
    <tr>
        <td class="Td1">状态：</td>
        <td><label id="lab_state"></label></td>
    </tr>
    <tr style="text-align: center">
        <td colspan="6">
            <input class="button" type="button" name="update" onclick="save()" value="保存">
            <input class="button" id="btn_start" type="button" onclick="start()" name="update" value="启用">
            <input class="button" id="btn_stop" type="button" onclick="stop()" name="update" value="禁用">
        </td>
    </tr>

</table>
</body>
</html>
